<?php

require_once(ABSPATH . 'manage/main.php');

class Manage extends Main {
	
	function Manage() {
		parent::Main();	
		$this->database();
		$this->lib('session', 'message');
	}
	
	function index() {
		$this->view('manage/index');
	}
	
	function today() {
		$this->message->set('欢迎登陆');
		$this->manage_view('manage/today');
	}
	
	function init_login() {
		$this->manage_view('manage/login');
	}
	
	function login() {
		extract($_POST);

		$manager = $this->db->find_row(
			"select m.id, m.name, m.passwd from manager m where m.name='$username'");
		
		// 登陆成功
		if( !empty($manager) && $manager['passwd'] == $passwd ) { 
			$data = array(
				'manager_id' => $manager['id'],
				'manager_name' => $manager['name']
			);
			$this->session->set_userdata( $data );
			redirect('manage/');
		}
		// 登陆失败
		else {
			$this->message->set("用户名或密码错误");
			$this->manage_view('manage/login');
		}
	}
	
	function logout() {
		$this->session->sess_destroy();
		redirect('manage/login');
	}
	
}

?>